package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.RxSupplier;
import com.ruoyi.system.mapper.RxSupplierMapper;
import com.ruoyi.system.service.IRxSupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.security.PermitAll;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 号码仓Controller
 *
 * @author hjf
 * @date 2025-02-18
 */
@RestController
@RequestMapping("/hmk/supplier")
public class RxSupplierController extends BaseController {
    @Autowired
    private IRxSupplierService rxSupplierService;

    @Autowired
    private RxSupplierMapper rxSupplierMapper;

    /**
     * 查询号码仓列表
     */
    @PreAuthorize("@ss.hasPermi('hmk:supplier:list')")
    @GetMapping("/list")
    public TableDataInfo list(RxSupplier rxSupplier) {
        startPage();
        List<RxSupplier> list = rxSupplierService.selectRxSupplierList(rxSupplier);
        return getDataTable(list);
    }

    /**
     * 导出号码仓列表
     */
    @PreAuthorize("@ss.hasPermi('hmk:supplier:export')")
    @Log(title = "号码仓", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RxSupplier rxSupplier) {
        List<RxSupplier> list = rxSupplierService.selectRxSupplierList(rxSupplier);
        ExcelUtil<RxSupplier> util = new ExcelUtil<RxSupplier>(RxSupplier.class);
        util.exportExcel(response, list, "号码仓数据");
    }


    @PermitAll
    @GetMapping("/listByIsProtective")
    public AjaxResult listByIsProtective(RxSupplier rxSupplier) {
        List<RxSupplier> list = rxSupplierMapper.listByIsProtective(rxSupplier);
        return AjaxResult.success(list);
    }


    /**
     * 获取号码仓详细信息
     */
    @PreAuthorize("@ss.hasPermi('hmk:supplier:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(rxSupplierService.selectRxSupplierById(id));
    }

    /**
     * 新增号码仓
     */
    @PreAuthorize("@ss.hasPermi('hmk:supplier:add')")
    @Log(title = "号码仓", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RxSupplier rxSupplier) {
        return toAjax(rxSupplierService.insertRxSupplier(rxSupplier));
    }

    /**
     * 修改号码仓
     */
    @PreAuthorize("@ss.hasPermi('hmk:supplier:edit')")
    @Log(title = "号码仓", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RxSupplier rxSupplier) {
        return toAjax(rxSupplierService.updateRxSupplier(rxSupplier));
    }

    /**
     * 删除号码仓
     */
    @PreAuthorize("@ss.hasPermi('hmk:supplier:remove')")
    @Log(title = "号码仓", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(rxSupplierService.deleteRxSupplierByIds(ids));
    }
}
